package com.baomidou.kisso.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.kisso.service.RxjavaService;

import io.reactivex.rxjava3.core.Single;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/rxjava")
@Slf4j
public class RxjavaController {

    @Autowired
    private RxjavaService rxjavaService;

    @GetMapping("/data")
    public Single<String> fetchData() {
        log.info("Fetching data...");
        Single<String> single = Single.create((emiter) -> {
            log.info("begin 。。。, 当前线程 ：{} ", Thread.currentThread().getName());
            // 在这里执行耗时的网络请求，例如调用外部 API
            rxjavaService.downAndUploadFile("wenjian ");
            emiter.onSuccess("Some data fetched from network");
            // 中文使用英文标点, 写代码速度都快了 ... 
            log.info("end 。。。, 当前线程 ：{} ", Thread.currentThread().getName());

        });

        return single;
    }

    @GetMapping("/data01")
    public String test01() {
        log.info("test01 data...");

        return "onSuccess";
    }

}
